package com.taxi.driver.module.main.mine.wallet;

import com.qianxx.utils.RxUtil;
import com.socks.library.KLog;
import com.taxi.driver.R;
import com.taxi.driver.common.BasePresenter;
import com.taxi.driver.data.user.UserRepository;
import com.taxi.driver.module.vo.MyWalletVO;

import javax.inject.Inject;

public class MyWalletPresenter extends BasePresenter implements MyWalletContract.Presenter {

    private MyWalletContract.View mView;
    private UserRepository mUserRepository;

    @Inject
    public MyWalletPresenter(UserRepository userRepository, MyWalletContract.View view) {
        mView = view;
        mUserRepository = userRepository;
    }

    @Override
    public void reqDriverInfo() {
        mUserRepository.refreshUserInfo();

        mUserRepository.getUserInfo()
                .map(MyWalletVO::createFrom)
                .compose(RxUtil.applySchedulers())
                .subscribe(myWalletVO -> mView.showDriverInfo(myWalletVO),
                        ex -> showNetworkError(ex, R.string.network_error, mView, mUserRepository));
    }

    @Override
    public void updateMsg(String uuid, int status) {
        mUserRepository.updateMsg(uuid, status)
                .compose(RxUtil.applySchedulers())
                .subscribe(entity -> mView.updateSuccess(uuid),
                        KLog::e);
    }
}
